package com.fick.util;

import java.io.File;

public class ShowFiles {
	
	public static String show(File file,String filepic,String dicpic,String prepic){
		
		if(!file.exists()){
			return "无";
		}
		StringBuffer content = new StringBuffer();
		content.append("<table>");
		content.append("<tr>" 
				+"<td colspan='10'>" 
				+"<div style='cursor:hand'><img src='"+prepic+"' width='40' height='40' onclick=\"showfiles('"+file.getParent().replaceAll("\\\\","\\\\\\\\")+"');\" /></div>" +
				"<hr></td>" 
				+"</tr>");
		
		File files[] = file.listFiles();
		if(files == null||files.length==0){
			return "无";
		}
		for(int i=0;i<files.length;i++){
			if(i%3==0){
				content.append("<tr>");
				//System.out.print("<tr>");
			}
			if(files[i].isFile()){ 
				if(files[i].getName().endsWith("jsp")||files[i].getName().endsWith("html")||files[i].getName().endsWith("htm")){
					content.append("<td align='center'><div style='cursor:hand'><img  onclick=\"showfile('"+files[i].getPath().replaceAll("\\\\","\\\\\\\\")+"');\"  width='30' height='30' src='"+filepic+"'/><br/></div>"+files[i].getName()+"</td>");
				}else{
					content.append("<td align='center'><div ><img onclick=\"showfile1('"+files[i].getPath().replaceAll("\\\\","\\\\\\\\")+"');\"   width='30' height='30' src='"+filepic+"'/><br/></div>"+files[i].getName()+"</td>");
				}
				
				//System.out.println("<td align='center'><img onclick='showfile();' width='40' height='40' src='"+filepic+"'/><br/>"+files[i].getName()+"</td>");
			}else{//������ļ��еĻ�?
				//show(files[i]);
				content.append("<td align='center'><div style='cursor:hand'><img  onclick=\"showfiles('"+files[i].getPath().replaceAll("\\\\","\\\\\\\\")+"');\" width='30' height='30' src='"+dicpic+"'/><br/></div>"+files[i].getName()+"</td>");
				//System.out.println("<td align='center'><img  onclick=\"showfiles('"+files[i].getPath().replaceAll("\\\\","\\\\\\\\")+"');\" width='40' height='40' src='"+dicpic+"'/><br/>"+files[i].getName()+"</td>");
			}
			if((i+1)%3==0){
				content.append("<tr/>");
				//System.out.println("<tr/>");
			}
		}
		content.append("</table>");
		return content.toString();
	}
	public static void main(String args[]){
		//ShowFiles.show(new File("c:\\"), "�ļ�ͼƬ", "�ļ���ͼƬ");
	}
}

